package com.study.test;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * description: Shiro 入门学习
 * @version v1.0
 * @author w
 * @date 2018年11月3日下午5:33:54
 **/
public class HelloShiro {
	
	private static final Logger logger = LoggerFactory.getLogger(HelloShiro.class);
	
	public static void main(String[] args) {
		Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini");
		// 获取安全管理器
		SecurityManager securityManager = factory.getInstance();
		// 存入到 SecurityUtils 中
		SecurityUtils.setSecurityManager(securityManager);
		
		// 获取 subject 用户主体
		Subject subject = SecurityUtils.getSubject();
		
		// 构造 UsernamePasswordToken 对象
		 UsernamePasswordToken token = new UsernamePasswordToken("shiro","1234");
		 
		 try {
			subject.login(token);
			logger.info("login success !");
		} catch (AuthenticationException e) {
			logger.error("login fialure " , e);
		}
		 
		 System.out.println("程序执行完毕。。。");
	}
	
	
}
